package com.coding.interceptors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptors implements HandlerInterceptor {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入拦截器");
//        String token = request.getHeader("token");
//        if (token == null) {
//            System.out.println("token不存在");
//            return false;
//        }
//
//        if (Boolean.TRUE.equals(redisTemplate.hasKey(token))) {
//            System.out.println("token存在");
//            return true;
//        }
//
//        response.setStatus(401);
//        return false;
        return true;
    }
}
